#!/root/.pyenv/shims/python

import rospy
from std_msgs.msg import String
import serial

def talker():
    ser = serial.Serial('/dev/scale', 9600, timeout=0.5)
    pub = rospy.Publisher('/weighing_scale/data', String, queue_size=20)
    rospy.init_node('weighing_scale', anonymous=False)
    rate = rospy.Rate(10)
    while not rospy.is_shutdown():
        ser.flushInput()
        while True:
            data = ser.readline().strip()
            if data:
                #print(data)
                pub.publish(data.split(' ')[-2])
            rate.sleep()

if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException:
        pass
